﻿#include <iostream>
class MoveObject{
public:
    int x;
};
class MonsterObject:public MoveObject{};
class MObject:public virtual MoveObject{};//虚基类

class NPCObject:public MoveObject{};
class WOLF :public MonsterObject {};
class MAN :public MonsterObject {};
class WOLFMAN :public WOLF,public MoveObject {};
int main()
{
    MonsterObject monster;
    //MoveObject* _move = &monster;//隐式类型转换，向上转型，若基类是private的话会报错
    MoveObject* _move = (MoveObject*) & monster;//强制转换
    //MonsterObject* _pmonster = _move;//报错，虽然_move指向的对象原本就是MonsterObject类，但是编译器不知道，向下转型不允许

    MonsterObject* _pmonster = (MonsterObject*)_move;//强制类型转换，因为经过思考，不是不小心
    //MonsterObject* _pmonsterA = static_cast<MonsterObject*>(_move);//显式转换，基类是private的话会报错

    //MonsterObject* _pmonsterB = (MObject*)_move;//强制转型报错，类是虚基类
    //MonsterObject* _pmonsterC = static_cast<MObject*>(_move);//显式转型报错，类是虚基类

    WOLFMAN wolfMan;

    void* ptr = &wolfMan;//WOLFMAN* -> void*，发生类型转换，变为空指针，内存信息丢失，只剩下内存
    //WOLF* pWlfA = ptr;//报错，类型丢失
    WOLF* pWlf = (WOLF*)ptr;//void* -> WOLF*，因为空指针内存信息丢失，只能转内存
    MAN* pMan = (MAN*)ptr;//void* -> MAN*，因为空指针内存信息丢失，只能转内存

    WOLF* pWlf1 = &wolfMan;//WOLFMAN* -> WOLF*，能完整转换信息
    //MAN* pMan1 = &wolfMan;//WOLFMAN* -> MAN*，能完整转换信息

    //std::cout << ptr << " " << pWlf1 << " " << pMan1 << std::endl;//003CF9D3 003CF9D3 003CF9D4
    
    _move = (WOLFMAN*)&wolfMan;//多重继承不能转换
    _move = (MoveObject*)&wolfMan;//多重继承不能转换
    _move = static_cast<MoveObject*>(&wolfMan);//多重继承不能转换，因为有多个MoveObject类，编译器不知道转哪一个

    wolfMan.::MoveObject::x = 3500;
    wolfMan.::WOLF::MonsterObject::MoveObject::x = 2500;
    
    std::cout << _move->x << std::endl;//3500，也就是说与WOLFMAN类继承的类中相对底层的父类赋值能成功

}
